package com.baor.service.security;

import com.baor.dao.UserDao;
import com.baor.domain.LoginUser;
import com.baor.domain.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserDao userDao;

    // 实现UserDetailsService接口的loadUserByUsername方法
    @Override
    public UserDetails loadUserByUsername(String userAccount) throws UsernameNotFoundException {
        UserVo vo = new UserVo();
        vo.setUserAccount(userAccount);
        vo = userDao.userLogin(vo);
        List<Integer> ids = userDao.roleIds(vo.getUserId());
        vo.setIds(ids);
        System.out.println("方法执行了");
        LoginUser loginUser = new LoginUser();
        loginUser.setVo(vo);
        return loginUser;
    }
}
